home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 61
/
061.d81
/
domino logic
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
9KB
|
252 lines
100 poke53281,0
110 print"[147]"chr$(142)"":gosub2280
120 rem *** load font
130 poke52,128:poke56,128:clr
140 poke147,0:sys57812"swapper.o",8,1:sys62631
145 sys57812"fnt1",8,0:poke780,0:poke781,0:poke782,128:sys65493
150 sys57812"fnt2",8,0:poke780,0:poke781,0:poke782,144:sys65493
160 ifpeek(783)and1thenprint"load error":end
170 rem *** init screen
175 poke53281,15:poke53280,15
180 poke56578,peek(56578)or3:poke56576,(peek(56576)and252)or1:poke648,136
185 dimcc%(12):fori=0to11:readcc%(i):next
187 data3,4,6,7,8,9,10,11,12,13,14,15
190 poke53272,32:i=rnd(0)
200 t1$="[144][147] 89<=[192][193][196][197][200][201]<=[204][205][208][209][212][213][216][217][220][221][160][161][146] by[\_[144]"
210 t1$=t1$+" :;>?[194][195][198][199][202][203]>?[206][207][210][211][214][215][218][219][255][223][162][163][146] dave]^[144] "
220 t1$=t1$+" johannsen":printt1$;
230 rem *** introduction
240 print" do you want instructions?"
250 geta$:ifa$=""then250
260 ifa$="y"thengosub1500
270 print" what size <2 to 9> [157][157]"
280 geta$:ifa$=""then280
290 s=asc(a$)-asc("0"):ifs<2ors>9then270
300 print" initializing... "
310 dims%(11,10),d%(11,10),t%(55),x%(55),y%(55),h%(55),n%(55):y=0
320 rem *** compute initial directions
330 y=y+1:x=0:ify>s+1then470
340 x=x+1:ifx>s+2then330
350 ifd%(x,y)>0then340
360 ifx=s+2then410
370 ify=s+1then420
380 ifd%(x,y+1)>0then420
390 ifd%(x+1,y)>0then410
400 ifrnd(1)>.5then420
410 d%(x,y)=2:d%(x,y+1)=1:goto340
420 j=d%(x+1,y):d%(x,y)=3:d%(x+1,y)=4:onj+1goto340,430,440,450,340
430 x=x+1:y=y-1:d%(x,y)=0:goto350
440 d%(x+1,y+1)=0:goto340
450 d%(x+2,y)=0:goto340
460 rem *** get random domino order
470 j=1:forx=0tos:fory=0tox:ifrnd(1)>.5then490
480 x%(j)=x:y%(j)=y:goto500
490 x%(j)=y:y%(j)=x
500 j=j+1:nexty,x:n=j-1:n1=0:n2=0
510 fori=1ton:j=int(rnd(1)*n+1):x=x%(i):x%(i)=x%(j):x%(j)=x:x=y%(i):y%(i)=y%(j)
520 y%(j)=x:next:i=1
530 rem *** put dominos in grid
540 forx=1tos+2:fory=1tos+1:ond%(x,y)goto580,560,570,580
550 print"program error!":goto580
560 s%(x,y)=x%(i):s%(x,y+1)=y%(i):i=i+1:goto580
570 s%(x,y)=x%(i):s%(x+1,y)=y%(i):i=i+1
580 d%(x,y)=0:nexty,x:print" "
590 rem *** print grid
600 poke34953-s,35:poke34958+s,36:poke35073+79*s,37:poke35078+81*s,38
610 fori=1to2*s+4:poke34953-s+i,33:poke35073+79*s+i,33:next
620 fori=1to2*s+2:poke34953-s+40*i,34:poke34958+s+40*i,34:next
630 fory=1tos+1:forx=1tos+2:i=34912-s+2*x+80*y:j=64+12*s%(x,y)
640 pokei,j:pokei+1,j+1:pokei+40,j+2:pokei+41,j+3:nextx,y
650 rem *** add dominos to the side
660 fory=0tos:forx=0toy:j=y*(y+1)/2+x:i=int(j/20):j=j-20*i:j=35010+40*j+2*i
670 pokej,236+x:pokej+1,246+y:nextx,y:x=1:y=1
680 poke35832,5:poke53271,0:poke53276,0:poke53277,0:poke53287,1:poke53269,1
690 rem *** add help
700 print"":fori=217to242:pokei,peek(i)or128:next
710 print"[144]c:color"
720 print"[144]h:help"
730 print"[144]u:undo"
740 print"[144]x:clear"
743 print"[144]e:erase"
745 print"[144]f:font"
746 print"[144]i:up"
747 print"[144]m:down"
748 print"[144]j:left"
749 print"[144]k:right"
750 print"[144]q:quit"
760 rem *** main loop
770 poke53249,66+16*y:x1=152-8*s+16*x:poke53248,x1and255:poke53264,x1/256
775 geta$
780 ifn1=nthen1920
790 j=31-(peek(56320)and31)
800 ifj=1ora$="[145]"theny=y+(y>1):goto770
810 ifj=2ora$=""theny=y-(y<=s):goto770
820 ifj=4ora$="[157]"thenx=x+(x>1):goto770
830 ifj=8ora$=""thenx=x-(x<=s+1):goto770
840 ifj=16ora$="e"thengosub1210:goto770
850 ifj=17ora$="i"thend=1:gosub990:goto770
860 ifj=18ora$="m"thend=2:gosub990:goto770
870 ifj=20ora$="j"thend=4:gosub990:goto770
880 ifj=24ora$="k"thend=3:gosub990:goto770
890 ifa$=""then770
900 ifa$<>"c"then910
905 cc=cc+1:ifcc>11thencc=0
907 poke53281,cc%(cc):poke53280,cc%(cc):goto770
910 ifa$="q"then1930
920 ifa$="h"thengosub2050:goto770
930 ifa$="x"thenforx=1tos+2:fory=1tos+1:gosub1210:nexty,x:x=1:y=1:goto770
935 ifa$="f"thensys828:goto770
940 ifa$<>"u"then770
950 j=0:fori=1ton:ifn%(i)>jthenj=n%(i):a=i
960 next:ifj=0then770
970 x=x%(a):y=y%(a):gosub1210:goto770
980 rem *** take square x,y in dir. d
990 ondgoto1000,1010,1020,1030
1000 e=2:x1=x:y1=y-1:on(y1<1)+2goto1190,1040
1010 e=1:x1=x:y1=y+1:on(y1>s+1)+2goto1190,1040
1020 e=4:x1=x+1:y1=y:on(x1>s+2)+2goto1190,1040
1030 e=3:x1=x-1:y1=y:ifx1<1then1190
1040 a=s%(x,y):b=s%(x1,y1):ifb<athenj=b:b=a:a=j
1050 ab=b*(b+1)/2+a+1:ift%(ab)then1370
1060 x%(ab)=x:y%(ab)=y:x=x1:y=y1:gosub1210:x=x%(ab):y=y%(ab):n1=n1+1:t%(ab)=1
1070 c=15:gosub2010:d%(x,y)=d:d%(x1,y1)=e:n2=n2+1:n%(ab)=n2
1080 j=64+12*s%(x,y):k=64+12*s%(x1,y1)
1090 i=34912-s+2*x+80*y:ondgoto1100,1120,1140,1160
1100 pokei-80,k+4:pokei-79,k+5:pokei-40,k+6:pokei-39,k+7
1110 pokei,j+10:pokei+1,j+11:pokei+40,j+6:pokei+41,j+7:goto1180
1120 pokei,j+4:pokei+1,j+5:pokei+40,j+6:pokei+41,j+7
1130 pokei+80,k+10:pokei+81,k+11:pokei+120,k+6:pokei+121,k+7:goto1180
1140 pokei,j+4:pokei+1,j+5:pokei+40,j+6:pokei+41,j+7
1150 pokei+2,k+8:pokei+3,k+5:pokei+42,k+9:pokei+43,k+7:goto1180
1160 pokei-2,k+4:pokei-1,k+5:pokei+38,k+6:pokei+39,k+7
1170 pokei,j+8:pokei+1,j+5:pokei+40,j+9:pokei+41,j+7
1180 j=peek(56320)and31:ifj<31then1180
1190 return
1200 rem *** remove domino at x,y
1210 ifd%(x,y)=0thenreturn
1220 i=34912-s+2*x+80*y:f=s%(x,y):j=64+12*f
1230 pokei,j:pokei+1,j+1:pokei+40,j+2:pokei+41,j+3
1240 ond%(x,y)goto1250,1270,1290,1310
1250 f1=s%(x,y-1):k=64+12*f1:d%(x,y-1)=0
1260 pokei-80,k:pokei-79,k+1:pokei-40,k+2:pokei-39,k+3:goto1330
1270 f1=s%(x,y+1):k=64+12*f1:d%(x,y+1)=0
1280 pokei+80,k:pokei+81,k+1:pokei+120,k+2:pokei+121,k+3:goto1330
1290 f1=s%(x+1,y):k=64+12*f1:d%(x+1,y)=0
1300 pokei+2,k:pokei+3,k+1:pokei+42,k+2:pokei+43,k+3:goto1330
1310 f1=s%(x-1,y):k=64+12*f1:d%(x-1,y)=0
1320 pokei-2,k:pokei-1,k+1:pokei+38,k+2:pokei+39,k+3
1330 iff>f1theni=f:f=f1:f1=i
1340 f2=f1*(f1+1)/2+f+1:t%(f2)=0:d%(x,y)=0:n%(f2)=0
1350 n1=n1-1:f2=b:b=f1:f1=a:a=f:c=0:gosub2010:a=f1:b=f2:return
1360 rem *** blink existing domino
1370 y1=y%(ab):x1=x%(ab):i=55392-s+2*x1+80*y1
1380 ond%(x1,y1)goto1390,1400,1410,1420
1390 j=i-80:goto1430
1400 j=i+80:goto1430
1410 j=i+2:goto1430
1420 j=i-1
1430 pokei,2:pokei+1,2:pokei+40,2:pokei+41,2
1440 pokej,2:pokej+1,2:pokej+40,2:pokej+41,2
1450 pokei,0:pokei+1,0:pokei+40,0:pokei+41,0
1460 pokej,0:pokej+1,0:pokej+40,0:pokej+41,0
1470 f=peek(56320)and31:iff<31then1430
1480 return
1490 rem *** intro message
1500 printt1$;""
1505 print" the rules of the game
1510 [153]"i will form a rectangle of dominos; and"
1520 [153]"then i will remember where each of the"
1530 [153]"numbers is located: i will then remove"
1540 [153]"the dominos: your job is to determine"
1550 [153]"how to place the dominos back to form"
1560 [153]"the rectangle: all of the dominoes in
1562 print"the stockpile on the right will be
1563 [153]"used and the grid will be completely
1564 print"covered:
1565 [153]"your answer may be different from mine:
1580 gosub 1880
1590 print"[145] using the joystick"
1600 print"put the square cursor over the half"
1610 print"of the domino you want to place; then;
1620 [153]"while pushing the firebutton; push the
1630 print"stick in the direction of the other
1640 [153]"half: pressing the button again will
1650 print"erase the domino:
1660 [153]" using the keyboard
1662 print"use the crsr keys to place the cursor
1670 [153]"and the i; j; k and m keys to place the
1675 print"domino: press e to erase the domino:
1680 [153]"if the domino has already been used;
1690 print"the matching domino will blink:
1695 [141]1880
1700 [153]"on the stockpile"
1710 [153]"to the right of the playing grid the
1720 print"unused dominoes are listed: if you
1730 [153]"press h for help; the dominoes that
1740 print"cannot be placed will turn red; and the
1750 [153]"dominoes that can only be placed in one
1760 print"position will be green:
1770 [153]"press c to change background color:
1780 print"press u to take back your last move:
1790 [153]"press x to clear the whole grid:
1800 print"press f to switch fonts:
1805 [153]"press q to quit to loadstar:
1810 gosub1880
1820 return
1870 rem *** wait for any key
1880 print"